---
title: "Nevada"
output: html_document
date: "2023-11-15"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(tidyverse)
library(dplyr)
library(patchwork)
library(scales)
library(haven)
library(lmtest)
library(gcookbook)
library(RColorBrewer)
library(viridis)
library(grid)

```


```{r}
setwd("~/Library/CloudStorage/Dropbox/Female Turnover/Nevada Short Article/LSQ/LSQ_data replication submission")

all <- read.csv("all_women.csv")

filtered_data <- all %>%
  filter(year >= 1950 & year <= 2023)

summarized_data <- filtered_data %>%
  group_by(year) %>%
  summarize(total_women = n()) %>%
  ungroup() %>%
  mutate(year = as.factor(year))

c <- ggplot(data = summarized_data, aes(x = year, y = total_women, group = 1)) +
  geom_line() + scale_x_discrete(breaks = c(1950,1960,1970,1980,1990,2000,2010,2020)) +
  labs(
    title = "Figure 1",
    subtitle = "Number of Women in State Legislatures, 1950-2023",
    y = "Total Number of Women",
    x = "Year"
  ) +
  theme_classic() +
  theme(
    axis.title = element_text(size = 20),
    axis.text.x = element_text(size = 20),
    axis.text.y = element_text(size = 20),
    title = element_text(size = 20)
  )
c
ggsave("total_wom.jpeg", plot = c, scale = 2, width = 10, height = 5, units = c("in"), dpi = 1000)
```


```{r}
setwd("~/Library/CloudStorage/Dropbox/Female Turnover/Nevada Short Article/LSQ/LSQ_data replication submission")
nevada <- read.csv("Nevada_exerpt.csv")

a <- ggplot(data= nevada, mapping = aes(year, pr_femseat)) + geom_line() +
    scale_x_continuous(breaks = c(2002,2004,2006,2008,2010,2012,2014,2016,2018,2020,2022)) +
  labs(title = "Figure 2", subtitle = "Percent Women Legislators in Nevada, 2002-2023",
       y = "Percent Women", 
       x = "Year") + theme_classic() +
  theme(
    axis.title = element_text(size = 20),    
    axis.text.x = element_text(size = 20),
    axis.text.y = element_text(size = 20),  
    title = element_text(size = 20))

a


ggsave("percent_fem_NV.jpeg", plot = a, scale = 2, width = 10, height = 5, units = c("in"), dpi = 1000)
```
```{r}
setwd("~/Library/CloudStorage/Dropbox/Female Turnover/Nevada Short Article/LSQ/LSQ_data replication submission")
demo <- read.csv("fem_demo.csv")
blue_to_green_palette <- colorRampPalette(c("lightgrey", "black"))
num_colors <- 6
colors <- blue_to_green_palette(num_colors)
agg_data <- demo %>%
  group_by(year, race_ethnicity) %>%
  summarize(total_women = n())

b <- ggplot(agg_data, aes(x = factor(year), y = total_women, fill = race_ethnicity)) +
  geom_bar(stat = "identity", width = .5) +
  scale_fill_manual(values = colors[1:6]) +
  labs(title = "Figure 3", fill = "Race/Ethnicity", x = "Year",
       y = "Total Number of Women") + theme_minimal() +
  theme(
    axis.title = element_text(size = 20),    
    axis.text.x = element_text(size = 20),
    axis.text.y = element_text(size = 20),  
    title = element_text(size = 20))

b

ggsave("fem_demo_NV.jpeg", plot = b, scale = 2, width = 10, height = 5, units = c("in"), dpi = 1000)
```

```{r}

setwd("~/Library/CloudStorage/Dropbox/Female Turnover/Nevada Short Article/LSQ/LSQ_data replication submission")

raw <- read.csv("all_women_party.csv")

filtered_data <- raw %>%
  filter(year >= 1950 & year <= 2023, party %in% c("Democrat", "Republican"))

summary_data <- filtered_data %>%
  group_by(year, party) %>%
  summarize(total_women = n())


q <- ggplot(summary_data, aes(x = year, y = total_women, linetype = party, group = party)) +
  geom_line(size = 1.2) +
  labs(
       x = "Year", y = "Number of Women") +
  scale_linetype_manual(values = c("solid", "dotted")) +
  theme_minimal() +
  theme(legend.title = element_blank())

q

ggsave("total_wom_party.jpeg", plot = q, scale = 2, width = 10, height = 5, units = c("in"), dpi = 1000)
```

```{r}
setwd("~/Library/CloudStorage/Dropbox/Female Turnover/Nevada Short Article/LSQ/LSQ_data replication submission")

raw <- read.csv("all_women_party.csv")

filtered_data <- raw %>%
  filter(year >= 1950 & year <= 2023, party %in% c("Democrat", "Republican"), state %in% c("Nevada - NV"))

summary_data <- filtered_data %>%
  group_by(year, party) %>%
  summarize(total_women = n())


z <- ggplot(summary_data, aes(x = year, y = total_women, linetype = party, group = party)) +
  geom_line(size = 1.2) +
  labs(
       x = "Year", y = "Number of Women") +
  scale_linetype_manual(values = c("solid", "dotted")) +
  theme_minimal() +
  theme(legend.title = element_blank())

z

ggsave("total_wom_party_NV.jpeg", plot = q, scale = 2, width = 10, height = 5, units = c("in"), dpi = 1000)

```

